package com.zh.custom.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.zh.custom.entity.TcusPresc;
import com.zh.custom.service.TcusPrescService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 客户处方表Controller
 * @author 690378361@163.com
 * @version 2025-08-31
 */
@Controller
@RequestMapping(value = "${adminPath}/custom/tcusPresc")
public class TcusPrescController extends BaseController {

	@Autowired
	private TcusPrescService tcusPrescService;


	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcusPresc get(Integer tid, boolean isNewRecord) {
		return tcusPrescService.get(tid, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("custom:tcusPresc:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcusPresc tcusPresc, Model model) {
		model.addAttribute("tcusPresc", tcusPresc);
		model.addAttribute("drList",);
		return "modules/custom/tcusPrescList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("custom:tcusPresc:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcusPresc> listData(TcusPresc tcusPresc, HttpServletRequest request, HttpServletResponse response) {
		tcusPresc.setPage(new Page<>(request, response));
		Page<TcusPresc> page = tcusPrescService.findPage(tcusPresc);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("custom:tcusPresc:view")
	@RequestMapping(value = "form")
	public String form(TcusPresc tcusPresc, Model model) {
		model.addAttribute("tcusPresc", tcusPresc);
		return "modules/custom/tcusPrescForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("custom:tcusPresc:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcusPresc tcusPresc) {
		tcusPrescService.save(tcusPresc);
		return renderResult(Global.TRUE, text("保存客户处方表成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("custom:tcusPresc:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcusPresc tcusPresc) {
		tcusPresc.setStatus(TcusPresc.STATUS_DISABLE);
		tcusPrescService.updateStatus(tcusPresc);
		return renderResult(Global.TRUE, text("停用客户处方表成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("custom:tcusPresc:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcusPresc tcusPresc) {
		tcusPresc.setStatus(TcusPresc.STATUS_NORMAL);
		tcusPrescService.updateStatus(tcusPresc);
		return renderResult(Global.TRUE, text("启用客户处方表成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("custom:tcusPresc:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcusPresc tcusPresc) {
		tcusPrescService.delete(tcusPresc);
		return renderResult(Global.TRUE, text("删除客户处方表成功！"));
	}
	
}